package com.health.controller.information;

import com.alibaba.dubbo.config.annotation.Reference;
import com.health.entity.PageResult;
import com.health.entity.QueryPageBean;
import com.health.entity.Result;
import com.health.pojo.Information;
import com.health.service.InformationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname Information
 * @Description TODO
 * @Version 1.0.0
 * @Date 2023/3/21 8:35
 * @Author RainGrd
 */
@RestController
@RequestMapping("/information")
@Slf4j
public class InformationController {


    @Reference
    private InformationService informationService;


    @RequestMapping("/findPage.do")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return informationService.queryInformationForPage(queryPageBean);
    }


    @RequestMapping("/findInformationById.do")
    public Result findInformationById(@RequestParam("id") Integer id) {
        return informationService.queryInformationById(id);
    }

    @RequestMapping("/addInformation.do")
    public Result addInformation(@RequestBody Information information) {
        try {
            int i = informationService.saveInformation(information);
            return i > 0 ? Result.success() : Result.error();
        } catch (Exception e) {
            log.info(e.getMessage());
            return Result.error();
        }

    }

    @RequestMapping("/editInformation.do")
    public Result editInformation(@RequestBody Information information) {
        try {
            int i = informationService.editInformation(information);
            return i > 0 ? Result.success() : Result.error();
        } catch (Exception e) {
            log.info(e.getMessage());
            return Result.error();
        }
    }


    @RequestMapping("/deleteInformation.do")
    public Result deleteInformation(Integer id) {
        try {
            int i = informationService.deleteInformation(id);
            return i > 0 ? Result.success() : Result.error();
        } catch (Exception e) {
            log.info(e.getMessage());
            return Result.error();
        }
    }

}
